package me.xue.communityhealth.service;

import com.github.pagehelper.Page;
import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.Information;
import me.xue.communityhealth.repo.InformationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationService implements BaseService<Information, Integer> {

    private final InformationRepository repository;

    @Autowired
    public InformationService(InformationRepository repository) {
        this.repository = repository;
    }

    @Override
    public int save(Information information) {
        return repository.save(information);
    }

    @Override
    public int update(Information information) {
        return repository.update(information);
    }

    @Override
    public int delete(Integer which) {
        return repository.delete(which);
    }

    public Information findOne(Integer which) {
        Information information = repository.findOne(which);
        if (information == null) {
            throw new ObjectNotFoundException();
        }
        return information;
    }

    @Override
    public Page<Information> pagedAll() {
        return repository.pagedAll();
    }

    @Override
    public List<Information> findAll() {
        return repository.findAll();
    }
}
